clear all
use npi_schools_weekly

replace is_bus = "0" if is_bus=="NA"
cap destring, replace

***Collapse to state-month-level data
gen year = 2020

gen month = 3 if fiscal_week==11 |fiscal_week==12|fiscal_week==13|fiscal_week==14
replace month = 4 if fiscal_week==15 |fiscal_week==18|fiscal_week==16|fiscal_week==17
replace month = 5 if fiscal_week==19 |fiscal_week==20|fiscal_week==21|fiscal_week==22

collapse is_* [aweight=popestimate2020], by(year state month)

compress
save npi_school_data_monthly, replace



*******************************************************
clear all
use npi_data_summer_2020_onwards

foreach var of varlist stayathomeorder mandatoryquarantinefortravelers nonessentialbusinessclosures largegatheringsban schoolclosures restaurantlimits facecoveringrequirement barclosures {
	replace `var' = 1 if `var'>1 & `var'!=.
}

encode state, gen(state_code)
tsset state_code date
tsfill
replace year = year(date)
replace month = month(date)
replace day = day(date)
replace state = state[_n-1] if state==""

foreach var of varlist stayathome-barclosures {
	replace `var' = l.`var' if `var'==.
}

compress

collapse (mean) stayathome-barclosures, by(state year month)

***Append earlier months derived from weekly data
append using npi_school_data_monthly

compress
save final_state_month_covid_npi, replace

